using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MobWayPointController : MonoBehaviour
{
	[SerializeField]
	private int randomPointInWalkPoint = 10;

	public static MobWayPointController instance;

	public MobWayPoint[] points;

	private int addCount;

	public void CalkWayPoints()
	{
		StopAllCoroutines();
		StartCoroutine(startCalk());
	}

	private void Awake()
	{
		instance = this;
	}

	private IEnumerator startCalk()
	{
		NavMeshPath path = new NavMeshPath();
		yield return null;
		MobWayPoint[] array = points;
		foreach (MobWayPoint point2 in array)
		{
			point2.CashRandomPoints(randomPointInWalkPoint);
		}
		MobWayPoint[] array2 = points;
		MobWayPointCahedWays casedWay = default(MobWayPointCahedWays);
		foreach (MobWayPoint point in array2)
		{
			point.wayPoints.Clear();
			foreach (MobWayPoint endPoint in point.nextPoints)
			{
				foreach (Vector3 cashedPoints1 in point.cashedPoints)
				{
					addCount = 0;
					foreach (Vector3 cashedPoints2 in endPoint.cashedPoints)
					{
						if (NavMesh.CalculatePath(cashedPoints1, cashedPoints2, 1111111111, path))
						{
							addCount++;
							casedWay.corners = new List<Vector3>(path.corners);
							casedWay.endMobWayPoint = endPoint;
							point.wayPoints.Add(casedWay);
						}
					}
				}
			}
		}
		Debug.Log("PATH CASHED");
	}
}
